package com.lz.football.module.task.item
{
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.liangzhong.constants.TaskConst;
	import com.liangzhong.constants.TipsConst;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.MainEvent;
	import com.liangzhong.events.TaskEvent;
	import com.liangzhong.model.task.TaskModuleType;
	import com.liangzhong.model.task.vo.TaskInfoVo;
	import com.lz.football.module.base.IComponent;
	import com.lz.football.module.task.view.TaskFinishView;
	
	import common.BaseView.IItemMouseEvent;
	
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.GlowFilter;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	import lz.controls.managers.TipsManager;
	
	import mx.messaging.AbstractConsumer;

	/**
	 *任务Item 
	 * @author Administrator
	 * 
	 */	
	public class TaskItem extends Sprite implements IComponent,IItemMouseEvent
	{
		/**
		 * 
		 */
		private var _text:TextField;
		/**
		 *任务信息 
		 */
		private var _taskVo:TaskInfoVo;
		/**
		 * 
		 */
		private var _shape:Shape;
		/**
		 *背景 
		 */
		private var _bg:MovieClip;
		
		public function TaskItem()
		{
			super();
		}
		
		public function initUI(view:Object=null):void
		{
			_bg = Reflection.createInstance("com.lz.modul.task.itemBg");
			this.addChild(_bg);
			_shape = new Shape();
			_shape.graphics.clear();
			_shape.graphics.beginFill(0x000000,0);
			_shape.graphics.drawRect(0,0,200,18);
			_shape.graphics.endFill();
//			this.addChild(_shape);
			_text = new TextField();
			_text.mouseWheelEnabled =false;
			_text.mouseEnabled= false;
			this.addChild(_text);
			_text.width = 200;
			_text.height = 20;
			this.buttonMode = true;
			
			
			var tf:TextFormat = new TextFormat();
			tf.underline = true;
			tf.size = 12;
			tf.bold = true;
			_text.defaultTextFormat = tf;
			addEvtListener();
		}
		/**
		 *设置数据 
		 * 
		 */
		public function setTaskDate($vo:TaskInfoVo):void
		{
			_taskVo = $vo;
			setType($vo.ntype);
			
		}
		/**
		 *设置类型 
		 * @param $type
		 * 
		 */
		public function setType($type:int):void
		{
			var glow:GlowFilter;
			switch($type)
			{
				case TaskConst.MAIN_TASK:
					_text.textColor = 0x00FF00
					glow = new GlowFilter(0x003300,1,2,2,0.5,BitmapFilterQuality.HIGH);
					setText("[主线]");
					break;
				case TaskConst.DAY_TASK:
					_text.textColor = 0xFFFFFF
					glow = new GlowFilter(0x0099CC,1,2,2,2,BitmapFilterQuality.HIGH);
					setText("[日常]");
					break;
			}
//			if(glow == null)return;
			_text.filters = [glow];
			
		}
		/**
		 *设置文本 
		 * @param $str
		 * 
		 */
		public function setText($str:String):void
		{
			_text.text  = $str + _taskVo.descplay + finishStatus()+ ""; 
			_text.width = _text.textWidth + 3;
			_shape.width = _text.textWidth + 3
		}
		/**
		 *任务完成状态  
		 * 
		 */
		private function finishStatus():String
		{
			if(_taskVo.f_value1 >= _taskVo.value1 && _taskVo.f_value2 >= _taskVo.value2 || _taskVo.status == TaskConst.TASK_FINISH)
			{
				return "(已完成)";
			}
			var str:String = "";
			if(/*_taskVo.f_value1 >= _taskVo.value1 &&*/ _taskVo.value1> 1)
			{
				str = _taskVo.f_value1 + "/" + _taskVo.value1;
			}
			if(/*_taskVo.f_value2 >= _taskVo.value2 && */_taskVo.value2 > 1)
			{
				str += _taskVo.f_value2 + "/" + _taskVo.value2;
			}
			return str;
		}
		public function addEvtListener():void
		{
			this.addEventListener(MouseEvent.ROLL_OUT,onMouseRollOut);
			this.addEventListener(MouseEvent.ROLL_OVER,onMouseRollOver);
			this.addEventListener(MouseEvent.CLICK,onMouseClick);
		}
		
		public function removeEvtListener():void
		{
		}
		
		public function destroyView():void
		{
		}
		/**
		 * 移出
		 * @param event
		 * 
		 */
		public function onMouseRollOut(event:MouseEvent):void
		{
			TipsManager.hide();
		}
		/**
		 * 移上
		 * @param event
		 * 
		 */
		public function onMouseRollOver(event:MouseEvent):void
		{
			TipsManager.show(TipsConst.TASKTIPS,_taskVo,15,15,false);
		}
		/**
		 *单击 
		 * @param event
		 * 
		 */
		public function onMouseClick(event:MouseEvent):void
		{
			if(_taskVo.f_value1 >= _taskVo.value1 && _taskVo.f_value2 >= _taskVo.value2 ||_taskVo.status == TaskConst.TASK_FINISH)
			{
				AppEventDispatcher.getInstance().dispatchEvent(new TaskEvent(TaskEvent.TASK_FINISH_TASK,{vo:_taskVo},true));
				return;
			}
			switch(_taskVo.clienttype)
			{
				case TaskModuleType.PREMATCH://预选赛
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_LEAGUEMATCH_VIEW));
					break;
				case TaskModuleType.EXPLORE://球员探索
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_EXPLORE_VIEW));
					break;
				case TaskModuleType.BAG://背包
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.Open_Bag_View));
					break;
				case TaskModuleType.BASEMATCH://联赛
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_LEAGUEMATCH_VIEW));
					break;
				case TaskModuleType.PLAYERCENTER://球员中心
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_PLAYERCENTER));
					break;
				case TaskModuleType.LADDERMATCH://天梯赛
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_LADDER_VIEW));
					break;
				case TaskModuleType.COURT://球场
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_COURT_VIEW));
					break;
				case TaskModuleType.TECHBAR://科技馆
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.Open_TechBar_View));
					break;
				case TaskModuleType.COMPETE://国家挑战赛
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_COMPETE_VIEW));
					break;
				case TaskModuleType.CLUB://俱乐部
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.Open_Club_View));
					break;
				case TaskModuleType.FRIEND://好友
					
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_FRIEND_VIEW));
					break;
			}
		}
		public function get tips():Object
		{
			return null;
		}
		/**
		 * 
		 * @param value
		 * 
		 */
		public function set tips(value:Object):void
		{
			
		}
	}
}